package utils;

import entity.ActualData;
import entity.item;
import entity.taskInfo;

import java.util.*;
import java.util.stream.Collectors;

public class seasonFactor {
    public  static double   predictTime(double baseTime, double a, double m, int repetition) {
        double learningTerm = m + (1 - m) * Math.pow(repetition, a);
        return learningTerm * baseTime;
    }
    public static void main(String[] args) {
        List<item> items = ExcelReader.readPartRecord(".\\src\\main\\resources\\resource\\物料数据3.xlsx");

        List<taskInfo> taskInfos = new ArrayList<>();
        taskInfos.addAll(ExcelReader.readTaskInfo(".\\src\\main\\resources\\resource\\1-3月任务.xlsx"));
        taskInfos.addAll(ExcelReader.readTaskInfo(".\\src\\main\\resources\\resource\\4-6月任务.xlsx"));
        taskInfos.addAll(ExcelReader.readTaskInfo(".\\src\\main\\resources\\resource\\7-8月任务.xlsx"));
        taskInfos.addAll(ExcelReader.readTaskInfo(".\\src\\main\\resources\\resource\\9-11月任务.xlsx"));
        taskInfos.addAll(ExcelReader.readTaskInfo(".\\src\\main\\resources\\resource\\11-12月任务.xlsx"));
        DataFilter dataFilter=new DataFilter();
        List<item> vaildItem=dataFilter.filterItems(items);
        List<taskInfo> vaildTaskInfo=dataFilter.filterTaskInfos(taskInfos,vaildItem);

        Map<Integer,List<taskInfo>> actualData=new HashMap<>();
        for(taskInfo taskInfo : vaildTaskInfo){
            Integer month=taskInfo.getDeadline().getMonthValue();
            actualData.computeIfAbsent(month,k->new ArrayList<>()).add(taskInfo);
        }
        System.out.println(actualData.size());
        final double M = 0.191309;
        final double alpha = -1.075812;
        double []totalProcessTime=new double[13];
        for (int k = 1; k <= 12; k++) {
            for (taskInfo actualdata : actualData.get(k)) {
                double baseMakeTime = actualdata.getTime();
                for (int r = 1; r <= actualdata.getTaskCount(); r++) {
                    totalProcessTime[k]+=predictTime(baseMakeTime, M, alpha, r);
                }
            }
        }
        double totaltime=0;
        for (int i = 1; i <=12; i++) {
            totaltime+=totalProcessTime[i];
            System.out.println(totalProcessTime[i]);
        }
        System.out.println(totaltime);
    }
}
